//
//  THCPCMyPublishDetailCell.m
//  YJB
//
//  Created by 中电大维 on 2017/1/5.
//  Copyright © 2017年 YJB. All rights reserved.
//

#import "THCPCMyPublishDetailCell.h"
NSString *const completeDetailID = @"completeDetailID";
@implementation THCPCMyPublishDetailCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        [self addSubview:self.iconImgView];
        [self addSubview:self.completeImageView];
        [self addSubview:self.titleLabel];
        [self addSubview:self.subtitleLabel];
        [self setFrame];
        
        [self completeDetailTest];
    }
    return self;
}

- (NSMutableAttributedString *)getAttributedString:(NSString *)front Middle:(NSString *)middle Behind:(NSString *)behind{
   
    NSMutableAttributedString *attr = [NSString attributedString:front frontColor:kUIColorFromRGB(0x333333) middle:middle middleColor:kUIColorFromRGB(0xff783c) behind:behind behindColor:kUIColorFromRGB(0x333333) font:FONT(15)];
    
    return attr;
}

- (void)setModel:(THCPCMyPublishDetailModel *)model
{
    _model = model;
    
    NSString *urlString = model.adv_icon;
    if (![urlString hasPrefix:@"http"])
        urlString = [@"http://" stringByAppendingString:urlString];
    [self.iconImgView sd_setImageWithURL:[NSURL URLWithString:urlString] placeholderImage:Image(@"th_cpc_default_normal")];

    self.completeImageView.hidden = [model.is_report intValue] == 1?YES:NO;
    self.titleLabel.text = model.adv_title;
    
    NSString *content = [NSString string];
    if (model.adv_title.length>12) {
        content = [NSString stringWithFormat:@"“%@...”",[model.adv_title substringToIndex:12]];
    }else{
        content = [NSString stringWithFormat:@"“%@”",model.adv_title];
    }
    self.subtitleLabel.attributedText = [self getAttributedString:@"参与" Middle:content Behind:@"任务"];
}

- (void)completeDetailTest
{
    self.titleLabel.text = @"18676727214";
    self.subtitleLabel.text = @"参与“只要轻松点几下，钱就到手...”任务";
    
    //    self.iconImgView.backgroundColor = [UIColor redColor];
    self.completeImageView.backgroundColor = [UIColor redColor];
}

- (void)setFrame{
    [self.iconImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top).offset(7);
        make.bottom.equalTo(self.mas_bottom).offset(-5);
        make.left.equalTo(self.mas_left).offset(12);
        make.width.equalTo(self.iconImgView.mas_height);
    }];
    
    [self.completeImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.iconImgView.mas_right).offset(-3);
        make.centerY.equalTo(self.iconImgView.mas_bottom).offset(-3);
        make.height.width.mas_equalTo(15);
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.iconImgView.mas_top);
        make.left.equalTo(self.iconImgView.mas_right).offset(10);
        make.right.equalTo(self.mas_right).offset(-12);
    }];
    [self.subtitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.mas_bottom).mas_offset(5);
        make.left.equalTo(self.titleLabel.mas_left);
        make.width.equalTo(self.titleLabel.mas_width);
        make.bottom.equalTo(self.mas_bottom).offset(-7);
    }];
}

-(UIImageView *)iconImgView
{
    if (!_iconImgView) {
        _iconImgView = [[UIImageView alloc] init];
        _iconImgView.image = Image(@"th_cpc_default_normal");
    }
    return _iconImgView;
}

-(UIImageView *)completeImageView
{
    if (!_completeImageView) {
        _completeImageView = [[UIImageView alloc] init];
        //_completeImageView.image = Image(@"cpc默认icon");
        [_completeImageView.layer setMasksToBounds:YES];
    }
    [_completeImageView.layer setMasksToBounds:_completeImageView.width*0.5];
    return _completeImageView;
}

-(UILabel *)titleLabel
{
    if (_titleLabel == nil)
    {
        _titleLabel = [[UILabel alloc]init];
        _titleLabel.backgroundColor = [UIColor clearColor];
        _titleLabel.font = [UIFont boldSystemFontOfSize:14];
        _titleLabel.numberOfLines = 0;
        _titleLabel.textColor = kUIColorFromRGB(0x666666);
        
    }
    return _titleLabel;
}

-(UILabel *)subtitleLabel
{
    if (_subtitleLabel == nil)
    {
        _subtitleLabel = [[UILabel alloc]init];
        _subtitleLabel.backgroundColor = [UIColor clearColor];
        _subtitleLabel.font = [UIFont boldSystemFontOfSize:15];
        _subtitleLabel.numberOfLines = 0;
        _subtitleLabel.textColor = kUIColorFromRGB(0x333333);
        //kUIColorFromRGB(0xec5023) kUIColorFromRGB(0x333333)
    }
    return _subtitleLabel;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
